package pabudr_se;

/**
 *
 * @author Drzycimski
 */
public class Vector2 {
    protected float x;
    protected float y;

    public Vector2() {}

    public Vector2(float x1, float x2) {
        this.x = x1;
        this.y = x2;
    }

    public float getX1() {
        return x;
    }

    public float getX2() {
        return y;
    }

    public void setX1(float x1) {
        this.x = x1;
    }

    public void setX2(float x2) {
        this.y = x2;
    }

    public void setX1X2(float x1, float x2) {
        this.x = x1;
        this.y = x2;
    }

    public Vector2 add(Vector2 rhs) {
        return new Vector2(this.x + rhs.x, this.y + rhs.y);
    }

    public Vector2 sub(Vector2 rhs) {
        return new Vector2(this.x - rhs.x, this.y - rhs.y);
    }

    public Vector2 mul(float s) {
        return new Vector2(s * this.x, s * this.y);
    }

    public float mul(Vector2 rhs) {
        return this.x * rhs.x + this.y * rhs.y;
    }

    public float len() {
        return (float) Math.sqrt(this.x * this.x + this.y * this.y);
    }

    public Vector2 norm() {
        final float len = this.len();
        return new Vector2(this.x/len, this.y/len);
    }

    @Override
    public String toString()
    {
        return "(" + this.x + " | " + this.y + ")";
    }
}
